package day03;

import java.util.*;

public class CollectionsDemo {
    public static void main(String[] args) {
        List<String> list = new LinkedList<>( );
        Collections.addAll(list, "A", "B", "C", "D", "E", "F", "G");
        list.forEach(System.out::println);//lambda表达式打印集合中的所有元素
        System.out.println("-------------------------1----------------");

        //打乱集合的顺序
        Collections.shuffle(list);
        list.forEach(System.out::println);
        System.out.println("---------------------------2--------------");

        test1();
    }
    public static  void test1(){
        List<Integer> list = new ArrayList<>( );
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        //按照倒序给集合排序
        Collections.sort(list);
        list.forEach(System.out::println);
        System.out.println("----------------------------3-------------");

        Collections.sort(list,new Comparator<Integer>(){
            @Override
            public int compare(Integer o1, Integer o2) {
                //倒序排
                return o2-o1;
            }
        });
        list.forEach(System.out::println);
        System.out.println("-----------------------------4------------");

        //让学生Students实现comparable接口,实现排序
        List<Student> students = new ArrayList<>( );
        students.add(new Student("小米",18));
        students.add(new Student("小ba",10));
        students.add(new Student("小a",8));

        Collections.sort(students);
        students.forEach(System.out::println);

    }
}
